<?php
namespace app\front\service\v2;
use app\front\service\GetMsgService;
use app\front\service\v2\Redis;
class gzhCallBack extends GetMsgService
{
    public function Notify(){
        $xmlData = getPost();
        $returnParams = [
            'return_code' => 'SUCCESS',
            'return_msg'  => 'OK'
        ];
        echo ArrToXml($returnParams);
        $arr = XmlToArr($xmlData);
        logs("return_Notify.txt", $arr);
        if(checkSign($arr)){
            $notify_data = ['total_fee'=>$arr['total_fee'],'openid'=>$arr['openid'],'out_trade_no'=>$arr['out_trade_no'],'return_code'=>$arr['return_code'],'result_code'=>$arr['result_code'],'sign'=>$arr['sign'],'create_time'=>date("Y-m-d H:i:s",time())];
            $redis=Redis::getInstance();
            $redis->rPush('NotifyMsgs2',json_encode($notify_data));
            $TemporaryMsg=$this->getTemporaryForMchId($arr['out_trade_no']);
            //插入红包记录
           // logs("NUM.txt", $TemporaryMsg['purpose']);
            if($TemporaryMsg['purpose']==3){
              
                $this->changeFilialeHb($TemporaryMsg);
            }else if($TemporaryMsg['purpose']==4){
                
                $this->changeShopHb($TemporaryMsg);
            }
           
            $this->insertRadPack($TemporaryMsg);
            //更改分公司奖池
           // $this->changeFilialeHb($TemporaryMsg);
            return $arr['out_trade_no'];
        }else{
            $TemporaryMsg=$this->getTemporaryForMchId($arr['out_trade_no']);
            $customer_id=$TemporaryMsg['open_id'];
            $store_id =$TemporaryMsg['store_id'];
            $moneyNum = $TemporaryMsg['total_fee'];
            $moneyNum= bcdiv($moneyNum,100,3);
            $this->order_add($arr['out_trade_no'],$customer_id, $store_id, $moneyNum,$statu=1,$desc='签名失败');
        }
        
    }
}

